home *** CD-ROM | disk | FTP | other *** search
/ Inside Multimedia 1994 April / Inside Multimedia CD-ROM (April 1994).iso / prg / gs / gs250.exe / TYPE1OPS.PS < prev    next >
Encoding:
Text File  |  1992-09-03  |  5.9 KB  |  167 lines

  1. %    Copyright (C) 1992 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % type1ops.ps
  21. % Define the Type 1 font opcodes for use by Ghostscript utilities.
  22.  
  23. % Define lenIV (the number of initial random bytes in the encoded outlines).
  24. % This should be zero, but we set it to 4 for compatibility with PostScript.
  25.  
  26. /lenIV 4 def
  27.  
  28. % Define the Type 1 opcodes we care about.
  29.  
  30. /Type1encode 18 dict
  31. /c_hstem 1 def   dup /hstem <01> put
  32. /c_vstem 3 def   dup /vstem <03> put
  33. /c_vmoveto 4 def   dup /vmoveto <04> put
  34. /c_rlineto 5 def   dup /rlineto <05> put
  35. /c_hlineto 6 def   dup /hlineto <06> put
  36. /c_vlineto 7 def   dup /vlineto <07> put
  37. /c_rrcurveto 8 def   dup /rrcurveto <08> put
  38. /c_closepath 9 def   dup /closepath <09> put
  39. /c_callsubr 10 def   /s_callsubr <0a> def   dup /callsubr s_callsubr put
  40. /c_return 11 def   dup /return <0b> put
  41. /c_escape 12 def
  42.   /ce_dotsection 0 def   /s_dotsection <0c06> def   dup /dotsection s_dotsection put
  43.   /ce_vstem3 1 def   /s_vstem3 <0c01> def   dup /vstem3 s_vstem3 put
  44.   /ce_hstem3 2 def   /s_hstem3 <0c02> def   dup /hstem3 s_hstem3 put
  45.   /ce_seac 6 def   /s_seac <0c06> def   dup /seac s_seac put
  46.   /ce_sbw 7 def   /s_sbw <0c07> def   dup /sbw s_sbw put
  47.   /ce_div 12 def   /s_div <0c0c> def   dup /div s_div put
  48.   /ce_callothersubr 16 def   /s_callothersubr <0c10> def   dup /callothersubr s_callothersubr put
  49.   /ce_pop 17 def   /s_pop <0c11> def   dup /pop s_pop put
  50.   /ce_setcurrentpoint 33 def   /s_setcurrentpoint <0c21> def   dup /setcurrentpoint s_setcurrentpoint put
  51. /c_hsbw 13 def   /s_hsbw <0d> def   dup /hsbw s_hsbw put
  52. /c_endchar 14 def   /s_endchar <0e> def   dup /endchar s_endchar put
  53. /c_rmoveto 21 def   dup /rmoveto <15> put
  54. /c_hmoveto 22 def   dup /hmoveto <16> put
  55.   /s_setcurrentpoint_hmoveto s_setcurrentpoint <8b16> concatstrings def
  56. /c_vhcurveto 30 def   dup /vhcurveto <1e> put
  57. /c_hvcurveto 31 def   dup /hvcurveto <1f> put
  58. def
  59.  
  60. % Define the encoding of numbers.
  61. /c_num1 32 def
  62. /c_num2 247 def
  63. /c_num3 251 def
  64. /c_num4 255 def
  65. /min_enc_num1 c_num1 c_num2 sub 1 add 2 idiv def
  66. /max_enc_num1 c_num2 c_num1 sub 1 sub 2 idiv def
  67. /min_enc_num2 max_enc_num1 1 add def
  68. /max_enc_num2 min_enc_num2 c_num3 c_num2 sub 256 mul add 1 sub def
  69. /min_enc_num3 max_enc_num2 neg def
  70. /max_enc_num3 min_enc_num2 neg def
  71.  
  72. % ------ CharString encoding ------ %
  73.  
  74. % For these utilities, a CharString is represented by an array.
  75. % Elements of the array are either integers or names.
  76. % Integers represent themselves; names are CharString operator names.
  77.  
  78. % Compute the length of a CharString.
  79. /charstring_length    % cs_array -> length
  80.  { 0 exch
  81.     { dup type /nametype eq
  82.        { Type1encode exch get length
  83.        }
  84.        { dup dup -107 ge exch 107 le and
  85.           { pop 1
  86.       }
  87.       { dup -1131 ge exch 1131 le and { 2 } { 5 } ifelse
  88.       }
  89.      ifelse
  90.        }
  91.       ifelse add
  92.     } forall
  93.  } bind def
  94.  
  95. % Write a CharString to a file.  Normally this will be a NullEncode filter
  96. % writing on a string of the correct length.
  97. /charstring_write    % file cs_array ->
  98.  { { dup type /nametype eq
  99.       { Type1encode exch get 1 index exch writestring
  100.       }
  101.       { dup dup -107 ge exch 107 le and
  102.          { 139 add
  103.      }
  104.      { dup dup -1131 lt exch 1131 gt or
  105.         { 1 index 255 write
  106.           2 copy -24 bitshift 255 and write
  107.           2 copy -16 bitshift 255 and write
  108.           2 copy -8 bitshift 255 and write
  109.           255 and
  110.         }
  111.         { dup 0 ge { 16#f694 } { neg 16#fa94 } ifelse add
  112.           2 copy -8 bitshift write 255 and
  113.         }
  114.        ifelse
  115.      }
  116.     ifelse 1 index exch write
  117.       }
  118.      ifelse
  119.    } forall pop
  120.  } bind def
  121.  
  122. % ------ CharString decoding ------ %
  123.  
  124. /Type1decode 256 array
  125. dup 0 32 getinterval
  126.   null /hstem null /vstem /vmoveto /rlineto /hlineto /vlineto
  127.   /rrcurveto /closepath /callsubr /return null /hsbw /endchar null
  128.   null null null null null /rmoveto /hmoveto null
  129.   null null null null null null /vhcurveto /hvcurveto
  130. 33 -1 roll astore pop
  131. dup 12
  132.  { dup read pop dup Type1escape exch known
  133.     { Type1escape exch get }
  134.     { pop null }
  135.    ifelse exch
  136.  } put
  137. 32 1 246 { 2 copy dup 139 sub put pop } for
  138. dup 247 { dup read pop 108 add exch } put
  139. dup 248 { dup read pop 364 add exch } put
  140. dup 249 { dup read pop 620 add exch } put
  141. dup 250 { dup read pop 876 add exch } put
  142. dup 251 { dup read pop 108 add neg exch } put
  143. dup 252 { dup read pop 364 add neg exch } put
  144. dup 253 { dup read pop 620 add neg exch } put
  145. dup 254 { dup read pop 876 add neg exch } put
  146. dup 255 { 0 4 { 8 bitshift 1 index read pop add } repeat exch } put
  147. def
  148. /Type1escape 9 dict
  149.   dup ce_dotsection /dotsection put
  150.   dup ce_vstem3 /vstem3 put
  151.   dup ce_hstem3 /hstem3 put
  152.   dup ce_seac /seac put
  153.   dup ce_sbw /sbw put
  154.   dup ce_div /div put
  155.   dup ce_callothersubr /callothersubr put
  156.   dup ce_pop /pop put
  157.   dup ce_setcurrentpoint /setcurrentpoint put
  158. def
  159.  
  160. % Decode a CharString (unencrypted) and push its elements on the stack.
  161. /charstring_read    % file -> {integer|name}*
  162.  { { dup read not { pop exit } if
  163.      Type1decode exch get
  164.      dup type /arraytype eq { exec } { exch } ifelse
  165.    } loop
  166.  } bind def
  167.